#!/bin/bash
function error {
    echo "$1"
    exit
}

dir=/data/yzw/formal/handle/hive_sql/shell/create_table_and_load_data

hive -e "drop database pre cascade;"
hive -e "drop database ods cascade;"
hive -e "drop database dim cascade;"
hive -e "drop database dwd cascade;"
hive -e "drop database dws cascade;"
hive -e "drop database ads cascade;"


hive -e "create database pre;"
hive -e "create database ods;"
hive -e "create database dim;"
hive -e "create database dwd;"
hive -e "create database dws;"
hive -e "create database ads;"


hive -f $dir/pre/pre.pre_area_code.sql  || error "pre_area_code.sql UNSUCCESS!!"
hive -f $dir/pre/pre.pre_yearbook_priority.sql || error "pre_yearbook_priority.sql UNSUCCESS!!"
echo "pre SUCCESSED"

hive -f $dir/ods/ods.ods_area_code.sql || error "ods_area_code.sql UNSUCCESS!!"
hive -f $dir/dim/dim.dim_area_code.sql || error "dim_area_code.sql UNSUCCESS!!"
hive -f $dir/ods/ods.ods_formal.sql || error "ods_formal.sql建表 UNSUCCESS!!"
#创建分区表
sh /data/yzw/formal/handle/load_formal_data/make_sql.sh || "formal建表语句生成失败"
#生成按分区加载的语句
hive -f /data/yzw/formal/handle/load_formal_data/formal.sql || error "formal.sql 按分区加载数据失败 UNSUCCESS!!"
#按照分区加载数据
hive -f $dir/ods/ods.ods_indicator_list.sql || error "ods_indicator_list.sql UNSUCCESS!!"
hive -f $dir/ods/ods.ods_indicator_synonyms.sql || error "ods_indicator_synonyms.sql UNSUCCESS!!"
hive -f $dir/ods/ods.ods_yearbook_priority.sql || error "ods_yearbook_priority.sql UNSUCCESS!!"
echo "ods SUCCESSED"

hive -f $dir/dim/dim.dim_unit_change.sql || error "dim_unit_change.sql UNSUCCESS!!"
echo "dim SUCCESSED"

hive -f $dir/dwd/dwd.dwd_formal.sql || error "dwd_formal.sql UNSUCCESS!!"
hive -f $dir/dwd/dwd.dwd_indicator_synonyms.sql || error "dwd_indicator_synonyms.sql UNSUCCESS!!"
hive -f $dir/dwd/dwd.dwd_yearbook_paixu.sql || error "dwd_yearbook_paixu.sql UNSUCCESS!!"
hive -f $dir/dwd/dwd.dwd_yearbook_paixu_other.sql || error "dwd_yearbook_paixu_other.sql UNSUCCESS!!"
hive -f $dir/dwd/dwd.dwd_get_finalindicatorame_and_zhidingunit_and_zhengshivalue_new.sql || error "dwd_get_finalindicatorame_and_zhidingunit_and_zhengshivalue_new.sql UNSUCCESS!!"
echo "dwd SUCCESSED"

hive -f $dir/dws/dws.dws_distinct_zhibiao_nian_diqu_old.sql || error "dws_distinct_zhibiao_nian_diqu.sql UNSUCCESS!!"
echo "dws SUCCESSED"

hive -f $dir/ads/ads.ads_distinct_zhibiao_nian_diqu.sql || error "ads_distinct_zhibiao_nian_diqu.sql UNSUCCESS!!"
hive -f $dir/ads/ads.ads_get_finalindicatorame_and_zhidingunit_and_zhengshivalue.sql || error "ads_get_finalindicatorame_and_zhidingunit_and_zhengshivalue.sql UNSUCCESS!!"
echo "ads SUCCESSED"

sh hdfs_to_local_toGB18030_to_tar.gz.sh || error "从hdfs拉取到本地，在本地转gb18030，并将结果压缩。失败！"

echo "hdfs_to_local_toGB18030_to_tar.gz.sh IS SUCCESSED!!"

#需要根据田老师给的服务器位置进行修改再运行
# sh trans_to_220.sh || error "传送到220节点,并解压缩"
# echo "sh trans_to_220.sh IS SUCCESSED!!"